#include "reg51.h" 
typedef unsigned int u16;
typedef unsigned char u8;
u8 word[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07};
#define DATA P0
#define CH P1

#define POS_A 0x01
#define POS_D 0x08
#define POS_F 0x20
#define POS_E 0x10
#define POS_B 0x02
#define POS_C 0x04
// ----------------------------------------------------------------------------------------
//                        function for delay
// ----------------------------------------------------------------------------------------
void delay ( u16 i)
{
    while(i--);
}

// ------------------------
// functions for display moving lines
// --------------------------
void display(u8 channel,u8 line_type)
{
    CH=channel;
    DATA=line_type;
    delay(10000); 
    CH=0;
    
}

// ------------------------
// function for display 1-8
// --------------------------
void display_1to8()
{
    u8 i;
    while(1) {
         for (i=0;i<8;i++)
              display(i , word[i]); 
    }
}



void display_moving_lines()
{
    u8 i=0;
    while(1){
		
        for(i=0;i<8;i++){
            display(i,POS_D);
        }
		i=7;
        display(i,POS_C);
        display(i,POS_B);
        
        for(i=7;i>0;i--){
            display(i,POS_A);
        }
		i=0;
        display(i,POS_F);
        display(i,POS_E);
		
		display(i,POS_E);
        display(i,POS_F);
		for(i=0;i<8;i++){
            display(i,POS_A);
        }
		i=7;
        display(i,POS_B);
        display(i,POS_C);
        
        for(i=7;i>0;i--){
            display(i,POS_D);
        }

    }
}
// ----------------------------------------------------------------------------------------
//                    main function
// ----------------------------------------------------------------------------------------


void main ()
{
    display_moving_lines();
    //display_1to8();
}